000100******************************************************************
000200*PROJECT  : STU-C
000300*AUTHOR   : Minh-Tuan Ta
000400*DATE     : 03/26/2012
000500*ABSTRACT : A program to add a student record to STUMST.DAT.
000600******************************************************************
000700 IDENTIFICATION DIVISION.
000800 PROGRAM-ID. STU-C.
000900 ENVIRONMENT DIVISION.
001000     SELECT IOFILE      ASSIGN TO "STUMST.DAT"
001100                         ORGANIZATION    IS INDEXED
001200                         ACCESS          IS RANDOM
001300                         RECORD KEY      IS IO-STUDENT-ID
001400                         ALTERNATE KEY   IS IO-LNAME WITH
001500                                         DUPLICATES
001600                         FILE STATUS     IS WS-STAT.
001700
001800     SELECT INZIP        ASSIGN TO "ZIPFILE.DAT"
001900                         ORGANIZATION    IS INDEXED
002000                         ACCESS          IS DYNAMIC
002100                         RECORD KEY      IS IN-ZIP
002200                         ALTERNATE KEY   IS IN-CITY WITH
002300                                         DUPLICATES
002400                         FILE STATUS     IS WS-ZIP-STAT.
002500
002600 DATA DIVISION.
002700 FILE SECTION.
002800 FD  IOFILE.
002900 01  STUDENT-RECORD.
003000     03  IO-STUDENT-ID      PIC 9(4).
003100     03  IO-FNAME           PIC X(20).
003200     03  IO-LNAME           PIC X(20).
003300     03  IO-STREET          PIC X(30).
003400     03  IO-ZIP             PIC X(5).
003500     03  IO-ACTIVE          PIC X.
003600 FD  INZIP.
003700 01  IN-REC.
003800     03  IN-ZIP              PIC X(5)    VALUE SPACES.
003900     03  IN-CITY             PIC X(30)   VALUE SPACES.
004000     03  IN-STATE            PIC X(2)    VALUE SPACES.
004100     03  IN-COUNTY           PIC X(30)   VALUE SPACES.
004200 WORKING-STORAGE SECTION.
004300 01  WS-STAT             PIC XX.
004400 01  WS-ZIP-STAT         PIC XX.
004500 01  WS-EOF              PIC X VALUE 'N'.
004600 01  WS-STUDENT-ID       PIC 9(4).
004700 01  WS-FNAME            PIC X(20).
004800 01  WS-LNAME            PIC X(20).
004900 01  WS-STREET           PIC X(30).
005000 01  WS-ZIP              PIC X(5).
005100 01  WS-ACTIVE           PIC X.
005200 01  WS-DATE.
005300     03  WS-YEAR         PIC 99.
005400     03  WS-MONTH        PIC 99.
005500     03  WS-DAY          PIC 99.
005600 01  WS-ERR              PIC X VALUE 'N'.
005700 01  WS-CONT             PIC X VALUE 'Y'.
005800 01  WS-FIRST            PIC X VALUE 'Y'.
       01  WS-CHG              PIC X.
005900
006000 SCREEN SECTION.
006100 01  INPUT-STUDENT-ID-SCRN.
006200         05  BLANK SCREEN.
006300         05  LINE 1  COL 01  VALUE "UPDATE STUDENT".
006400         05          COL 73  PIC 9(2) FROM WS-MONTH.
006500         05          COL 75  VALUE "/".
006600         05          COL 76  PIC 9(2) FROM WS-DAY.
006700         05          COL 78  VALUE "/".
006800         05          COL 79  PIC 9(2) FROM WS-YEAR.
006900         05  LINE 2  COL 37  VALUE "UPDATE STUDENT".
007000
007100         05  LINE 4  COL 15  VALUE "STUDENT ID TO UPDATE".
007200         05          COL 40  PIC 9(4) TO WS-STUDENT-ID.
007300         05  LINE 6  COL 34  VALUE "(ENTER 0000 TO EXIT)".
007400
007500 01  INPUT-SCRN.
007600         05  BLANK SCREEN.
007700         05  LINE 1  COL 01  VALUE "UPDATE STUDENT".
007800         05          COL 73  PIC 9(2) FROM WS-MONTH.
007900         05          COL 75  VALUE "/".
008000         05          COL 76  PIC 9(2) FROM WS-DAY.
008100         05          COL 78  VALUE "/".
008200         05          COL 79  PIC 9(2) FROM WS-YEAR.
008300         05  LINE 2  COL 37  VALUE "UPDATE STUDENT".
008400         05  LINE 4  COL 15  VALUE "STUDENT ID TO UPDATE".
008500         05          COL 40  PIC 9(4) FROM WS-STUDENT-ID.
008600
008700         05  INPUT-FNAME-SCRN.
008800             10  LINE 5  COL 20  VALUE "STUDENT FIRST NAME".
008900             10          COL 40  PIC X(20) FROM IO-FNAME.
009000             10  LINE 6  COL 40  PIC X(20) TO WS-FNAME.
009100             10          COL 40  PIC X(20) FROM WS-FNAME.
009200         05  INPUT-LNAME-SCRN.
009300             10  LINE 7  COL 20  VALUE "STUDENT LAST NAME".
009400             10          COL 40  PIC X(20) FROM IO-LNAME.
009500             10  LINE 8  COL 40  PIC X(20) TO WS-LNAME.
009600             10          COL 40  PIC X(20) FROM WS-LNAME.
009700         05  INPUT-STREET-SCRN.
009800             10  LINE 9  COL 20  VALUE "STREET".
009900             10          COL 40  PIC X(30) FROM IO-STREET.
010000             10  LINE 10 COL 40  PIC X(30) TO WS-STREET.
010100             10          COL 40  PIC X(30) FROM WS-STREET.
010200         05  INPUT-ZIP-SCRN.
010300             10  LINE 11 COL 20  VALUE "ZIP".
010400             10          COL 40  PIC X(5) FROM IO-ZIP.
010500             10  LINE 12 COL 40  PIC X(5) TO WS-ZIP AUTO.
010600             10          COL 40  PIC X(5) FROM WS-ZIP.
010700             10  LINE 13  COL 20  VALUE "CITY".
010800             10          COL 40  PIC X(30) FROM IN-CITY.
010900             10  LINE 14 COL 20  VALUE "STATE".
011000             10          COL 40  PIC X(2) FROM IN-STATE.
011100             10  LINE 15 COL 20  VALUE "COUNTY".
011200             10          COL 40  PIC X(30) FROM IN-COUNTY.
011300
011400         05  INPUT-ACTIVE-SCRN.
011500             10  LINE 16 COL 20  VALUE "ACTIVATE (Y/N)?".
                   10          COL 40  PIC X FROM IO-ACTIVE.
011600             10  LINE 17 COL 40  PIC X TO WS-ACTIVE AUTO.
011700         05  LINE 19     COL 34 VALUE "(LEAVE BLANK TO KEEP OLD VA
011800-            "LUES)".

       01  CHG-SCRN.
           03  BLANK SCREEN.
           03  LINE 4  COL 20  VALUE "STUDENT ID".
           03          COL 40  PIC 9(4) FROM IO-STUDENT-ID.
           03  LINE 5  COL 20  VALUE "STUDENT FIRST NAME".
           03          COL 40  PIC X(20) FROM IO-FNAME.
           03  LINE 6  COL 20  VALUE "STUDENT LAST NAME".
           03          COL 40  PIC X(20) FROM IO-LNAME.
           03  LINE 7  COL 20  VALUE "STREET".
           03          COL 40  PIC X(30) FROM IO-STREET.
           03  LINE 8  COL 20  VALUE "ZIP".
           03          COL 40  PIC X(5) FROM IO-ZIP.
           03  LINE 9  COL 20  VALUE "CITY".
           03          COL 40  PIC X(30) FROM IN-CITY.
           03  LINE 10 COL 20  VALUE "STATE".
           03          COL 40  PIC X(2) FROM IN-STATE.
           03  LINE 11 COL 20  VALUE "COUNTY".
           03          COL 40  PIC X(30) FROM IN-COUNTY.

           03  LINE 12 COL 20  VALUE "ACTIVATE".
           03          COL 40  PIC X FROM IO-ACTIVE AUTO.

           03  LINE 14 COL 32  VALUE "DO YOU WANT TO UPDATE THIS RECORD
      -    "(Y/N)?".
           03          COL 30  PIC X TO WS-CHG AUTO.

           01  CONTINUE-SCRN.
               03  BLANK SCREEN.
               03  LINE 9  COL 32 VALUE "DO YOU WANT TO CONTINUE(Y/N)?".
               03          COL 64 PIC X TO WS-CONT AUTO.

011900
012000 01  ERROR-SCRN.
012100     03  BLANK SCREEN.
012200     03  LINE 12 COL 32 VALUE "ERROR UPDATING RECORD".
012300     03  LINE 14 COL 32 VALUE "FILE STATUS:".
012400     03          COL 46 PIC XX FROM WS-STAT.
012500     03  LINE 15 COL 32 VALUE "RECORD KEY:".
012600     03          COL 46 PIC X(8) FROM WS-STUDENT-ID.
012700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
012800     03          COL 47 PIC X TO WS-CONT AUTO.
012900
013000 01  ERROR-ZIP-SCRN.
013100     03  BLANK SCREEN.
013200     03  LINE 12 COL 32 VALUE "INVALID ZIP CODE".
013300     03  LINE 14 COL 32 VALUE "FILE STATUS:".
013400     03          COL 46 PIC XX FROM WS-ZIP-STAT.
013500     03  LINE 15 COL 32 VALUE "RECORD KEY:".
013600     03          COL 46 PIC X(8) FROM IN-ZIP.
013700     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
013800     03          COL 47 PIC X TO WS-CONT AUTO.
013900
014000 01  SUCCESS-SCRN.
014100     03  BLANK SCREEN.
014200     03  LINE 12 COL 32 VALUE "RECORD UPDATED SUCCESSFULLY".
014300     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
014400     03          COL 47 PIC X TO WS-CONT AUTO.


014500
014600
014700 PROCEDURE DIVISION.
014800 100-MAIN.
014900     ACCEPT WS-DATE FROM DATE
015000     OPEN    INPUT INZIP
015100             I-O   IOFILE
015200
015300     MOVE SPACES TO WS-ZIP
015400     MOVE ZEROS TO WS-STUDENT-ID
015500     MOVE SPACES TO WS-FNAME
015600     MOVE SPACES TO WS-LNAME
015700     MOVE SPACES TO WS-STREET
015800     MOVE SPACES TO WS-ZIP
015900
016000
016100     MOVE 'Y' TO WS-FIRST
016200     MOVE 'Y' TO WS-CONT
016300
016400     PERFORM 200-UPDATE
016500     UNTIL (WS-STUDENT-ID = ZEROS AND WS-FIRST = 'N')
016600     OR WS-CONT = 'N'
016700
016800     CLOSE IOFILE
016900     CLOSE INZIP
017000
017100     EXIT PROGRAM.
017200
017300 200-UPDATE.
017400     MOVE SPACES TO WS-ZIP
017500     MOVE ZEROS TO WS-STUDENT-ID
017600     MOVE SPACES TO WS-FNAME
017700     MOVE SPACES TO WS-LNAME
017800     MOVE SPACES TO WS-STREET
017900     MOVE SPACES TO WS-ZIP
018000
018100     MOVE 'N' TO WS-FIRST
018200     DISPLAY INPUT-STUDENT-ID-SCRN
018300     ACCEPT INPUT-STUDENT-ID-SCRN
018400
018500     MOVE "N" TO WS-ERR
018600
018700     IF NOT WS-STUDENT-ID = ZEROS
018800
018900         MOVE WS-STUDENT-ID TO IO-STUDENT-ID
019000
019100         READ IOFILE
019200             INVALID KEY MOVE "Y" TO WS-ERR
019300         END-READ
019400
019500         IF NOT WS-ERR = "Y"
019600
019700
019800             MOVE IO-ZIP TO IN-ZIP
019900
020000             START INZIP KEY = IN-ZIP
020100             END-START
020200
020300             READ INZIP NEXT RECORD
020400             END-READ
020500
020600             DISPLAY INPUT-SCRN
020700
020800             ACCEPT INPUT-FNAME-SCRN
020900             ACCEPT INPUT-LNAME-SCRN
021000             ACCEPT INPUT-STREET-SCRN
021100             ACCEPT INPUT-ZIP-SCRN
021200
021300*Look for the zip
021400
                   IF WS-ZIP = SPACES
                       MOVE IO-ZIP TO IN-ZIP
                   ELSE
021500                 MOVE WS-ZIP TO IN-ZIP
                   END-IF
021600
021700             MOVE 'N' TO WS-ERR
021800
021900             START INZIP KEY = IN-ZIP
022000                 INVALID KEY
022100                     MOVE 'Y' TO WS-ERR
022200             END-START
022300
022400             IF NOT WS-ERR = 'Y'
022500
022600*get the zip record and accept the active
022700
022800                 READ INZIP NEXT RECORD
022900                 END-READ
023000
023100                 DISPLAY INPUT-SCRN
023200
023300
023400                 ACCEPT INPUT-ACTIVE-SCRN
023500
023600                 IF NOT WS-FNAME = SPACES
023700                     MOVE WS-FNAME           TO IO-FNAME
023800                 END-IF
023900
024000                 IF NOT WS-LNAME = SPACES
024100                     MOVE WS-LNAME           TO IO-LNAME
024200                 END-IF
024300
024400                 IF NOT WS-STREET = SPACES
024500                     MOVE WS-STREET          TO IO-STREET
024600                 END-IF
024700
024800                 IF NOT WS-ZIP = SPACES
024900                     MOVE WS-ZIP             TO IO-ZIP
                       ELSE
                           MOVE IO-ZIP TO IN-ZIP
025000                 END-IF
025100
025200                 IF NOT WS-ACTIVE = SPACES
025300                     MOVE WS-ACTIVE          TO IO-ACTIVE
025400                 END-IF
025500
                       DISPLAY CHG-SCRN
                       ACCEPT CHG-SCRN

                       IF WS-CHG = 'Y'
                           MOVE 'N' TO WS-ERR

                           REWRITE STUDENT-RECORD
                               INVALID KEY MOVE 'Y' TO WS-ERR
                           END-REWRITE

                           IF WS-ERR = 'Y'
                               DISPLAY ERROR-SCRN
                               ACCEPT ERROR-SCRN
                           ELSE
                               DISPLAY SUCCESS-SCRN
                               ACCEPT SUCCESS-SCRN
                           END-IF
                       ELSE
                           DISPLAY CONTINUE-SCRN
                           ACCEPT CONTINUE-SCRN
                       END-IF
026900
027000             ELSE
027100                 DISPLAY ERROR-ZIP-SCRN
027200                 ACCEPT ERROR-ZIP-SCRN
027300             END-IF
027400
027500         ELSE
027600             DISPLAY ERROR-SCRN
027700             ACCEPT ERROR-SCRN
027800         END-IF
027900     END-IF.
028000
